﻿//-----------------------------------------------------------------------
// <copyright file="ArgumentHelperTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System.Collections.Generic;
using System.Linq;
using GateShift.Servers.GameServer;
using GateShift.Servers.GameServer.HelperClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace GateShift.Testing.Servers.GameServer.HelperClasses
{
    /// <summary>
    /// Unit Test Class for ArgumentHelperTest
    /// </summary>
    [TestClass]
    public class ArgumentHelperTest
    {
        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region ProcessArguments

        /// <summary>
        /// Test for ProcessArguments on Invalid Arguments
        /// </summary>
        [TestMethod]
        public void ProcessArguments_InvalidArgument()
        {
            string[] arguments = new[]
                {
                    "-lasdjlfhaskldjfhasdlkjfhasdjklfhasdkljfasdhf"
                };

            List<ArgumentAction> processedArguments = ArgumentHelper.ProcessArguments(arguments);

            Assert.AreEqual(1, processedArguments.Count());
            Assert.IsTrue(processedArguments.Contains(ArgumentAction.InvalidArgument));
        }

        /// <summary>
        /// Test for ProcessArguments on the ConsoleMode argument
        /// </summary>
        [TestMethod]
        public void ProcessArguments_ConsoleMode()
        {
            string[] arguments = new[]
                {
                    "--console",
                    "-c"
                };

            IEnumerable<ArgumentAction> processedArguments = ArgumentHelper.ProcessArguments(arguments);

            Assert.AreEqual(1, processedArguments.Count(), "Expected only 1 command");
            Assert.IsTrue(processedArguments.Contains(ArgumentAction.ConsoleMode));
        }

        /// <summary>
        /// Test for ProcessArguments on the PrintHelp argument
        /// </summary>
        [TestMethod]
        public void ProcessArguments_PrintHelp()
        {
            string[] arguments = new[]
                {
                    "--help",
                    "-h",
                    "-?"
                };

            IEnumerable<ArgumentAction> processedArguments = ArgumentHelper.ProcessArguments(arguments);

            Assert.AreEqual(1, processedArguments.Count(), "Expected only 1 command");
            Assert.IsTrue(processedArguments.Contains(ArgumentAction.PrintHelp));
        }

        #endregion

        #region SplitArguments

        /// <summary>
        /// Test for SplitArguments on 1 argument
        /// </summary>
        [TestMethod]
        public void SplitArguments_OneArgument()
        {
            const string ToParse = "\"One Argument\"";

            List<string> arguments = ArgumentHelper.SplitArguments(ToParse);

            Assert.AreEqual(1, arguments.Count);
            Assert.AreEqual("One Argument", arguments[0]);
        }

        /// <summary>
        /// Test for SplitArguments on 2 arguments
        /// </summary>
        [TestMethod]
        public void SplitArguments_TwoArguments()
        {
            const string ToParse = "Two Arguments";

            List<string> arguments = ArgumentHelper.SplitArguments(ToParse);

            Assert.AreEqual(2, arguments.Count);
            Assert.AreEqual("Two", arguments[0]);
            Assert.AreEqual("Arguments", arguments[1]);
        }

        /// <summary>
        /// Test for SplitArguments on a missing end quote
        /// </summary>
        [TestMethod]
        public void SplitArguments_MissingEndQuote()
        {
            const string ToParse = "Missing \"The End Quote";

            List<string> arguments = ArgumentHelper.SplitArguments(ToParse);

            Assert.AreEqual(2, arguments.Count);
            Assert.AreEqual("Missing", arguments[0]);
            Assert.AreEqual("The End Quote", arguments[1]);
        }

        /// <summary>
        /// Test for SplitArguments on a quote in the middle
        /// </summary>
        [TestMethod]
        public void SplitArguments_QuoteInMiddle()
        {
            const string ToParse = "Quote \"In The\" Middle";

            List<string> arguments = ArgumentHelper.SplitArguments(ToParse);

            Assert.AreEqual(3, arguments.Count);
            Assert.AreEqual("Quote", arguments[0]);
            Assert.AreEqual("In The", arguments[1]);
            Assert.AreEqual("Middle", arguments[2]);
        }

        #endregion
    }
}